import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: () => import(/* webpackChunkName: "home" */ '../views/home.vue'),
    meta: {
      alive: true
    }
  },
  {
    path: '/setting',
    name: 'setting',
    component: () => import(/* webpackChunkName: "setting" */ '../views/setting.vue'),
    meta: {
      alive: true
    }
  },
  {
    path: '/sec',
    name: 'result',
    component: () => import(/* webpackChunkName: "setting" */ '../views/sec.vue'),
    meta: {
      alive: true
    }
  },
  {
    path: '/detail',
    name: 'detail',
    component: () => import(/* webpackChunkName: "setting" */ '../views/detail.vue'),
    meta: {
      alive: true
    }
  },

  {
    path: '/generalPurposeDebugger',
    name: 'generalPurposeDebugger',
    component: () => import(/* webpackChunkName: "setting" */ '../views/generalPurposeDebugger.vue'),
    meta: {
      alive: true
    }
  },
  {
    path: '/download',
    name: 'download',
    component: () => import(/* webpackChunkName: "setting" */ '../views/support/download.vue'),
    meta: {
      alive: true
    }
  },
  {
    path: '/customization',
    name: 'customization',
    component: () => import(/* webpackChunkName: "setting" */ '../views/support/customization.vue'),
    meta: {
      alive: true
    }
  },
  {
    path: '/aboutus',
    name: 'aboutus',
    component: () => import(/* webpackChunkName: "setting" */ '../views/support/aboutus.vue'),
    meta: {
      alive: true
    }
  },
  {
    path: '/qa',
    name: 'qa',
    component: () => import(/* webpackChunkName: "setting" */ '../views/support/qa.vue'),
    meta: {
      alive: true
    }
  },
  {
    path: '/cart',
    name: 'cart',
    component: () => import(/* webpackChunkName: "setting" */ '../views/support/cart.vue'),
    meta: {
      alive: true
    }
  },
  {
    path: '/pay',
    name: 'pay',
    component: () => import(/* webpackChunkName: "setting" */ '../views/support/pay.vue'),
    meta: {
      alive: true
    }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "setting" */ '../views/login/login.vue'),
    meta: {
      alive: false
    }
  }, {
    path: '/register',
    name: 'register',
    component: () => import(/* webpackChunkName: "setting" */ '../views/login/register.vue'),
    meta: {
      alive: false
    }
  }, {
    path: '/forget',
    name: 'forget',
    component: () => import(/* webpackChunkName: "setting" */ '../views/login/forget.vue'),
    meta: {
      alive: false
    }
  }, {
    path: '/user',
    name: 'user',
    component: () => import(/* webpackChunkName: "setting" */ '../views/user.vue'),
    meta: {
      alive: true
    }
  },

 



]


// 捕获push replace中的错误
// 当然在replace中的错误也是可以相同的进行捕获
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
// push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch(err => err)
}


const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  scrollBehavior: () => ({ y: 0 }), //滚动到顶端
  routes
})

export default router
